﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Com.CMS263.BLL;
using Com.CMS263.PO;
using Com.CMS263.Util;

namespace Com.CMS263.Web.manage.MessageManage
{
    public partial class MessageShow : System.Web.UI.Page
    {
        public PO.Message mes = new Com.CMS263.PO.Message();
        MessageBLL mbll = new MessageBLL();
        public int page = 1;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                try
                {
                    page = Convert.ToInt32(Request["page"]);
                    if (page == 0)
                    {
                        page = 1;
                    }
                }
                catch (Exception)
                {
                    page = 1;
                }

                int id = Convert.ToInt32(Request["id"]);
                if (id > 0)
                {
                    mes = (PO.Message)mbll.FindModelById("Message", id);
                    mes.IsRead = true;
                    mbll.entity = mes;
                    mbll.UpDate();
                }
                else
                {
                    StringUtil.Alert("没有找到相关信息，请核实", "MessageList.aspx");
                }
            }
        }

        protected void btnReply_Click(object sender, EventArgs e)
        {
            

        }

        protected void btnSave_Click(object sender, EventArgs e)
        {
            string con = StringUtil.checkStr(Request["txtMessage"]);
            int id = Convert.ToInt32(Request["id"]);
            if (id > 0)
            {
                mes = (PO.Message)mbll.FindModelById("Message", id);
                mes.IsReply = false;
                mes.ReplyCon = con;
                if (!string.IsNullOrEmpty(mes.ReplyCon))
                {
                    mes.IsReply = true;
                }
                mbll.entity = mes;
                if (mbll.UpDate())
                {
                    StringUtil.Alert("回复成功", "messagelist.aspx?page=" + page);
                }
                else
                {
                    StringUtil.Alert("回复失败", "-1");
                }
            }
        }
    }
}
